// https://leetcode.cn/problems/find-resultant-array-after-removing-anagrams/description/
package main

func counter(word string, rec map[rune]int){
	for _, val := range word{
		rec[val] += 1
	}
}


func isEqual(rec1, rec2 map[rune]int) bool {
	if len(rec1) != len(rec2){
		return false
	}
	for k, v := range rec1 {
		if v != rec2[k]{
			return false
		}
	}
	return true
}

func removeAnagrams(words []string) []string {
	var stack []string
	stack = append(stack, words[0])
	rec0 := make(map[rune]int)
	counter(words[0], rec0)
    for i := 1; i < len(words); i++ {
		rec1 := make(map[rune]int)
		counter(words[i], rec1)
		if isEqual(rec0, rec1) {
			continue
		}
		stack = append(stack, words[i])
		rec0 = rec1
	}
	return stack
}